

import { lazy, Suspense, useEffect } from "react";
import { Outlet, useRoutes, createBrowserRouter,useNavigate } from 'react-router-dom';
import { SmileOutlined, UserOutlined, CopyOutlined, PictureOutlined } from '@ant-design/icons'
import Home from '../page/home/index'

// const Home = lazy(() => import('../page/home/index'));
const Mine = lazy(() => import('../page/min/index'));
const Todo = lazy(() => import('../page/todo/index'));
const Couse = lazy(() => import('../page/couse/couse'));
const My = lazy(() => import('../page/my/index'));
const Drag = lazy(() => import('../page/drag/index'));
const Echarts = lazy(() => import('../page/echarts/echarts'));
const Serch = lazy(() => import('../page/serch/serch'));
const User = lazy(() => import('../page/user/user'));
const Register = lazy(() => import('../page/register/register'));
const Del = lazy(() => import('../components/404'));



function checkLocalStorage() {  
  const token = localStorage.getItem('LPFdenglu');  
  return token ? true : false;  
}

// useEffect(()=>{
//   const token = localStorage.getItem('LPFdenglu');  
//   if(!checkLocalStorage){

//   }
// },[token])


const routes = [
  {
    path: '/',
    key: '/',
    element: <User/>,
    icon: <SmileOutlined />,
    islogin: 0
  },
  {
    path: '/home',
    key: '/home',
    label: '用户管理',
    element: <Home />,
    icon: <UserOutlined />,
    islogin: 1,
    guards: [checkLocalStorage]
  },
  {
    path: '/mine',
    key: '/mine',
    label: '信息管理',
    icon: <CopyOutlined />,
    element: <Mine />,
    islogin: 1,
  },
  {
    path: '/shop',
    key: '/shop',
    // element: <My />,
    label: '商品管理',
    icon: <SmileOutlined />,
    islogin: 1,
    children: [
      {
        path: 'todo',
        key: 'todo',
        // element: <Todo />,
        element: (
          <Suspense fallback={<></>}>
            <Todo />
          </Suspense>
        ),
        label: '课程管理',
        icon: <PictureOutlined />,
        islogin: 1,
      },
      {
        path: 'my',
        key: 'my',
        // element: <My />,
        element: (
          <Suspense fallback={<></>}>
            <My />
          </Suspense>
        ),
        label: '成员管理',
        icon: <SmileOutlined />,
        islogin: 1,
      }
    ]
  },
  {
    path: '/couse',
    key: '/couse',
    element: <Couse />,
    label: '操作管理',
    icon: <SmileOutlined />,
    islogin: 1,
  },
  {
    path: '/drag',
    key: '/drag',
    element: <Drag />,
    label: '地图管理',
    icon: <SmileOutlined />,
    islogin: 1,
  },
  {
    path: '/echarts',
    key: '/echarts',
    element: <Echarts />,
    label: '图表管理',
    icon: <SmileOutlined />,
    islogin: 1,
  },
  {
    path: '/serch',
    key: '/serch',
    element: <Serch />,
    label: '历史记录',
    icon: <SmileOutlined />,
    islogin: 1,
  },
  {
    path: '/user',
    key: '/user',
    element: <User/>,
    // icon: <SmileOutlined />,
    islogin: 0
  },
  {
    path: '/register',
    key: '/register',
    element: <Register />,
    // label: '历史记录',
    // icon: <SmileOutlined />,
    islogin: 0,
  },
  {
    path: '*',
    key: '/del',
    element: <Del/>,
    // label: '历史记录',
    // icon: <SmileOutlined />,
    islogin: 0,
  }
]

export default routes;